from typing import List
from collections import defaultdict
from math import ceil
class Solution:
    def countMajoritySubarrays(self, nums: List[int], target: int) -> int:
        bit = [1 if nums[i]==target else 0 for i in range(len(nums))]
        acc_sum = [0]
        for i in range(0, len(bit)):
            acc_sum.append(acc_sum[-1]+bit[i])
        count = 0
        for i in range(0, len(acc_sum)):
            for j in range(i+1, len(acc_sum)):
                if acc_sum[j]-acc_sum[i] >= ceil((j-i+1)/2):
                    count += 1
        return count

print(Solution().countMajoritySubarrays([1,2,2,3], 2))